package com.raymond.cmpp.codec.cmpp2.encodeing;

import com.raymond.client.codec.encodeing.BaseEncoder;
import com.raymond.client.msg.BaseMessage;
import com.raymond.client.utils.NettyByteBufUtil;
import com.raymond.cmpp.codec.annotation.MsgCodec;
import com.raymond.cmpp.enums.CommandIdType;
import com.raymond.cmpp.msg.response.DeliverResponseMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * 状态报告和上行响应编码
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-08-10 15:15
 */
@MsgCodec(commandId = CommandIdType.DELIVER_RESPONSE)
public class DeliverResponseMessageEncoder extends BaseEncoder {
    @Override
    public byte[] encode0(BaseMessage msg) throws Exception {
        DeliverResponseMessage responseMessage = (DeliverResponseMessage) msg;
        ByteBuf bodyBuffer = Unpooled.buffer();
        bodyBuffer.writeLong(responseMessage.getMsgId());
        bodyBuffer.writeByte(responseMessage.getResult());
        return NettyByteBufUtil.toArray(bodyBuffer);
    }
}
